{
    //只要等号两边模式相同左边变量就会赋予对饮的值
    let [a, b, c] =[1, 2, 3];//等效于let a=1,let b=2,let c=3
// console.log(a);
    let [foo, [[bar],baz]] = [1,[[2],3]];//foo=1 bar=2 baz=3
   // console.log(foo);
   //  let [x,,y] = [1,2,3];//x=1, y=3
    // console.log(y);
    let [head,...tail] = [1,2,3,4,5,6];
    // console.log(tail);[2,3,4,5,6]
    let [x, y, ...z] = ['a'];//x=a,y=undefined,z=[]
    // console.log(y);

}
{
    // set结构,也可以使用数组解构赋值
    let [x,y,z] = new Set(['a','b','c']);//x=a,y=b,z=c
    // console.log(z)//c
}

{
    //解构赋值允许制定默认的值
    let [foo =true] = [];//true
    // console.log(foo);
    let [x, y='1'] =['1']//x=1,y=1
    let [a,b='b'] = ['a', undefined];
    // console.log(b);//b
    function f(){
        console.log('aaa');
    }
    let [c=f()]=[1];
    // console.log(c);//方法不执行,因为x能拿到值,所以方法根本不执行
}

{
    //对象解构赋值(左右两边属性必须一致否则没法赋值)
    let{foo,bar} = {foo:'aaa', bar:'bb'};
    // console.log(foo);//aaa
    let{foo:baz} = {foo:'aaa'};
    // console.log(baz);//baz=aaa;
    //变量名和属性名
    let obj = {first:'hell', last:'world'};
    let{first:f, last:l} = obj;
    // console.log(l);//world
    //对已经申明的变量进行赋值
    let c;
    ({c} = {c:1})
    // console.log(c);1
    let {log,sin,cos} = Math;
    // console.log(sin);
}
{
    //字符串也可以解构赋值
    let[a,b,c,d,e] = 'hello';
    // console.log(e);//o
    let{length:len} = 'kllklk';
    // console.log(len);//6
}

{
    //返回一个数组
    function example(){
        return [1,2,3];
    }
    let[a,b,c] = example();//a=1,b=2,c=3
    // console.log(b);//2
}
{
    //遍历map解构
    const map = new Map();
    map.set('12','23');
    map.set('1','2');

    for(let[k,v] of map){
        // console.log(k);
        // console.log(v);
    }
}

